//
//  ZJMoreFiTrateView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/11/22.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJMoreFiTrateView.h"
#import "ZJFiltrateView.h"
@interface ZJMoreFiTrateView ()
{
    NSArray *_titleArray;
}

@end

@implementation ZJMoreFiTrateView

- (instancetype)initWithFrame:(CGRect)frame titleArray:(NSArray *)titleArray
{
    self = [super initWithFrame:frame];
    if (self) {
        _titleArray = titleArray;
        self.backgroundColor = [UIColor themeGrayColor];
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    CGFloat width = (self.width - (_titleArray.count - 1)) / _titleArray.count;
    for (int i = 0; i < _titleArray.count; i ++) {
        ZJFiltrateView *view = [[ZJFiltrateView alloc] initWithFrame:CGRectMake(i * (width + 1) , 0, width, self.height) title:_titleArray[i]];
        view.tag =  ZJMoreFiTrateViewTAG + i;
        UITapGestureRecognizer *tapGester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_tapGester:)];
        [view addGestureRecognizer:tapGester];
        [self addSubview:view];
    }
    
    UIView *underView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height - 1, self.width, 1)];
    underView.backgroundColor = [UIColor viewBGGrayColor];
    [self addSubview:underView];
}

- (void)action_tapGester:(UITapGestureRecognizer *)tapGester{
    if (self.delegate) {
        [self.delegate ZJMoreFiTrateViewDelegate_clickWithTag:tapGester.view.tag];
    }
}

- (void)setupLableWithString:(NSString *)string ToTag:(NSInteger)tag{
    ZJFiltrateView *view = [self viewWithTag:tag];
    view.title = string;
}

@end
